//
//  YHY_TravelNotesTableViewCell.m
//  Travels
//
//  Created by yanghuiyan on 16/3/22.
//  Copyright © 2016年 yanghuiyan. All rights reserved.
//

#import "YHY_TravelNotesTableViewCell.h"
#import "UIImageView+WebCache.h"
#define Width self.contentView.frame.size.width
#define Height self.contentView.frame.size.height
@implementation YHY_TravelNotesTableViewCell

- (void)dealloc {
    
    [_titleLabel release];
    [_backImageView release];
    [_userImageView release];
    [_dateLabel release];
    
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:self.backImageView];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.titleLabel.numberOfLines = 2;
        self.titleLabel.textColor = [UIColor whiteColor];
        [self.backImageView addSubview:self.titleLabel];
        
        self.dateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.dateLabel.textColor = [UIColor whiteColor];
        [self.backImageView addSubview:self.dateLabel];
        
        self.userImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.backImageView addSubview:self.userImageView];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.backImageView.frame = CGRectMake(15, 5, self.contentView.frame.size.width - 30, self.contentView.frame.size.height - 10);
    
    self.titleLabel.frame = CGRectMake(15, 20, self.backImageView.frame.size.width - 40, 40);
    
    self.dateLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 20, self.titleLabel.frame.size.width, 20);
    
    self.userImageView.frame = CGRectMake(self.titleLabel.frame.origin.x, self.contentView.frame.size.height / 4 * 3 - 15, 45, 45);
    //为图片加边框 变圆
    self.userImageView.layer.cornerRadius = 5;
    self.userImageView.layer.masksToBounds = YES;
    self.userImageView.layer.borderWidth = 2;
    self.userImageView.layer.borderColor = [[UIColor colorWithRed:226/255.0 green:227/255.0 blue:228/255.0 alpha:1] CGColor];
    
}

- (void)setTravelModel:(TravelNotesModel *)travelModel {
    
    _travelModel = travelModel;
    
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:travelModel.front_cover_photo_url] placeholderImage:[UIImage imageNamed:@"21"]];
    
    [_userImageView sd_setImageWithURL:[NSURL URLWithString:travelModel.userNew.image]placeholderImage:[UIImage imageNamed:@"23"]];
    
    _titleLabel.text = travelModel.name;
    
    if (travelModel.start_date !=nil ) {
        _dateLabel.text = [NSString stringWithFormat:@"%@/%@天,%@图", travelModel.start_date, travelModel.days, travelModel.photos_count];
    }else {
        _dateLabel.text = [NSString stringWithFormat:@"%@天,%@图", travelModel.days, travelModel.photos_count];
    }
    
    
}

- (void)setSearchModel:(SearchModel *)searchModel {
    if (_searchModel != searchModel) {
        [_searchModel release];
        _searchModel = [searchModel retain];
    }
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.front_cover_photo_url] placeholderImage:[UIImage imageNamed:@"21"]];
    [_userImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.searchUser.image] placeholderImage:[UIImage imageNamed:@"23"]];
    _titleLabel.text = searchModel.name;
    _dateLabel.text = [NSString stringWithFormat:@"%@ / %@天 / %@图",searchModel.start_date, searchModel.days, searchModel.views_count];
    
}


@end
